﻿using Sustainalytics.ESGRatings.BusinessLogic.Computing.Utils;
using Sustainalytics.ESGRatings.DataContract;
using System.Collections.Generic;
using System.Linq;

namespace Sustainalytics.ESGComputing.Service.Validators
{
    public class DataSetValidator : Validator<ESGDataContainer>
    {
        public override ICollection<string> BrokenRules(ESGDataContainer entity)
        {
            if (entity.IndicatorTemplates.IsNullOrEmpty())
            {
                BrokenRulesList.Add("Invalid indicator list");
            }

            if (entity.Companies.IsNullOrEmpty())
            {
                BrokenRulesList.Add("Empty companies list");
            }

            if (entity.CompaniesScores.IsNullOrEmpty())
            {
                BrokenRulesList.Add("Empty raw scores list");
            }

            if (entity.ReferenceUniverses.IsNullOrEmpty())
            {
                BrokenRulesList.Add("Reference Universe list is empty");
            }

            if (entity.Matrices.IsNullOrEmpty())
            {
                BrokenRulesList.Add("Empty weight matrix list");
            }
            else
            {
                BrokenRulesList.AddRange(
                    from matrix in entity.Matrices
                    where matrix.CompaniesWeights.IsNullOrEmpty()
                    select $"Matrix with id {matrix.MatrixId} is invalid");
            }

            return BrokenRulesList;
        }
    }
}